Make IGC reader more robust on nonsense input.
authorRobert Lipe <robertlipe@gpsbabel.org>
Fri, 30 Jun 2017 17:28:30 +0000 (12:28 -0500)
committerRobert Lipe <robertlipe@gpsbabel.org>
Fri, 30 Jun 2017 17:28:30 +0000 (12:28 -0500)
igc.cc

diff --git a/igc.cc b/igc.cc
index 449a751178d285d79be5b2dc9493aed1d2fc7a79..a501363c23e578d615e2c54862795f889a6694a7 100644 (file)
--- a/igc.cc
+++ b/igc.cc
@@ -170,7 +170,7 @@ static void igc_task_rec(const char* rec)
   // First task record identifies the task to follow
   if (id == state) {
     task_desc[0] = '\0';
-    if (sscanf(rec, "C%2u%2u%2u%2u%2u%2u%6[0-9]%4c%2u%[^\r]\r\n",
+    if (sscanf(rec, "C%2u%2u%2u%2u%2u%2u%6[0-9]%4c%2u%79[^\r]\r\n",
                &tm.tm_mday, &tm.tm_mon, &tm.tm_year,
                &tm.tm_hour, &tm.tm_min, &tm.tm_sec,
                flight_date, task_num, &num_tp, task_desc) < 9) {
@@ -187,15 +187,14 @@ static void igc_task_rec(const char* rec)
     // Create a route to store the task data in.
     rte_head = route_head_alloc();
     rte_head->rte_name = task_num;
-    sprintf(tmp_str, DATEMAGIC "%s: %s", flight_date, task_desc);
-    rte_head->rte_desc = tmp_str;
+    rte_head->rte_desc = QStringLiteral(DATEMAGIC) + flight_date + QStringLiteral(": ") + task_desc;
     route_add_head(rte_head);
     state++;
     return;
   }
   // Get the waypoint
   tmp_str[0] = '\0';
-  if (sscanf(rec, "C%2u%2u%3u%1[NS]%3u%2u%3u%1[WE]%[^\r]\r\n",
+  if (sscanf(rec, "C%2u%2u%3u%1[NS]%3u%2u%3u%1[WE]%79[^\r]\r\n",
              &lat_deg, &lat_min, &lat_frac, lat_hemi,
              &lon_deg, &lon_min, &lon_frac, lon_hemi, tmp_str) < 8) {
     fatal(MYNAME ": task waypoint (C) record parse error\n%s", rec);